<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/pages/commons/path.jsp"%>

<script type="text/javascript">
	function isValid() {
		$('#id').validatebox({
			required : true,
			missingMessage : '请输入有效的数据库编号！'
		});
		if (!$('#id').validatebox('isValid'))
			return false;
		$('#dbName').validatebox({
			required : true,
			missingMessage : '请输入有效的数据库名！'
		});
		if (!$('#dbName').validatebox('isValid'))
			return false;
		$('#dbType').validatebox({
			required : true,
			missingMessage : '请输入有效的类型！'
		});
		if (!$('#dbType').validatebox('isValid'))
			return false;
		$('#dbUrl').validatebox({
			required : true,
			missingMessage : '请输入有效的地址！'
		});
		if (!$('#dbUrl').validatebox('isValid'))
			return false;
		$('#dbAccount').validatebox({
			required : true,
			missingMessage : '请输入有效的账号！'
		});
		if (!$('#dbAccount').validatebox('isValid'))
			return false;
		$('#dbPwd').validatebox({
			required : true,
			missingMessage : '请输入有效的密码！'
		});
		if (!$('#dbPwd').validatebox('isValid'))
			return false;

		return true;
	}

	function save() {
		if (!isValid())
			return;
			var id = $.trim($('#id').val());
			var dbName = $.trim($('#dbName').val());
			var dbType = $.trim($('#dbType').val());
			var dbUrl = $.trim($('#dbUrl').val());
			var dbAccount = $.trim($('#dbAccount').val());
			var dbPwd = $.trim($('#dbPwd').val());

		$.ajax({
			type : 'post',
			url : '${ctx}/adminManage/sys/autoDb/doUpdate.do',
			data : {
					id : id,
					dbName : dbName,
					dbType : dbType,
					dbUrl : dbUrl,
					dbAccount : dbAccount,
					dbPwd : dbPwd
			},
			dataType : 'json',
			success : function(data) {
				var result = data.result;
				if (result == 'success') {
					$.messager.alert('提示', '操作成功！', 'info');

					$('#editDiv').dialog('close');
					$('#dataTable').treegrid('reload');
					$('#dataTable').treegrid('clearChecked');
				} else {
					$.messager.alert('提示', '操作失败！<br />' + data.error, 'error');
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$.messager.alert('提示', '操作失败！<br />' + errorThrown, 'error');
			}
		});
	}
	
	function cancel() {
		$('#editDiv').dialog('close');
	}
</script>

<table class="table2">
	<tr>
		<td>数据库编号：</td>
		<td>
			<input id="id" type="text" value="${info.id}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td>数据库名：</td>
		<td>
			<input id="dbName" type="text" value="${info.dbName}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td>类型：</td>
		<td>
			<input id="dbType" type="text" value="${info.dbType}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td>地址：</td>
		<td>
			<input id="dbUrl" type="text" value="${info.dbUrl}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td>账号：</td>
		<td>
			<input id="dbAccount" type="text" value="${info.dbAccount}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td>密码：</td>
		<td>
			<input id="dbPwd" type="text" value="${info.dbPwd}" style="width: 200px" />
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
			<a id="saveButton" class="easyui-linkbutton" icon="icon-ok" onclick="save()">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" onclick="cancel()">取消</a>
		</td>
	</tr>
</table>